/**
 * 
 */
/***************************************************************
                           病人管理模块
***************************************************************/
var addPthlgyDialog;
function pthlgyManagerInit()
{
	 $("#pthlgyTable tr:nth-child(even)").addClass("trevencolor");
	 BUI.use(['bui/overlay','bui/form'],function(Overlay,Form){
	      	var form = new Form.HForm({
	        	srcNode : '#form'
   	 }).render();
	 
	 addPthlgyDialog = new Overlay.Dialog({
         title:'编辑患者病理信息',
         width:500,
         height:560,
         //配置DOM容器的编号
         contentId:'pthlgy_content',
         cancel:function(){
	      	choose_close();
	      	clearPthlgyDialog();
	     },
         success:function () {
        	 UpdatePthlgy();
           }
       });
   });
	 pthlgySearchInit();
}

/**
 *  编辑患者
 */
function UpdatePthlgy()
{
	addPthlgyDialog.close();
	var url = projectName + "/pthlgy/saveOrUpdate.do?postDate=" + new Date().getTime();
	$.ajax({
		url: url,
		type: "post",
		async: false,
		data: $('#pthlgyForm').serialize(),
		success: function(data,result)
		{
				if("ERROR" == data){
					messageAlert(1,"修改患者病理信息失败，请重试",function()
							{
								this.close();
								choose_close();
								showPthlgyPageDataList(1);
					});
				}
				else
				{
					messageAlert(1,"修改患者病理信息成功",function()
							{
								this.close();
								choose_close();
								showPthlgyPageDataList(1);
					});
				}
		}
	});
}

/**
 *	清空表单数据 
 */
function clearPthlgyDialog(){
	$("#pthlgy_id").val();
	$("#pthlgy_mrn").val("");
	$("#pthlgy_name").val("");
	$("input[name='tumor_site']").attr("checked",false);
	$("input[name='dffrnttn']").attr("checked",false);
	$("input[name='tnm']").attr("checked",false);
	$("input[name='pathology']").attr("checked",false);
	$("input[name='egfr']").attr("checked",false);
	$("input[name='smoke']").attr("checked",false);
	$("#medical_history").val("");
}



/**
 *	编辑患者 
 */
function pthlgyEdit(mrn)
{
	$.ajax({
		url : projectName+"/pthlgy/getPthlgyByMrn.do?date=" + new Date().getTime(),
		async : false,
		data:{"mrn":mrn},
		success : function(data) {
			if(null != data&&data != "")
			{
				clearPthlgyDialog();
				$("#pthlgy_id").val(data.id);
				$("#pthlgy_mrn").val(data.mrn);
				$("#pthlgy_name").val(data.name);
				$("input[name='tumor_site'][value="+data.tumor_site+"]").attr("checked",true);
				$("input[name='dffrnttn'][value="+data.dffrnttn+"]").attr("checked",true);
				$("input[name='tnm'][value="+data.tnm+"]").attr("checked",true);
				$("input[name='pathology'][value="+data.pathology+"]").attr("checked",true);
				$("input[name='egfr'][value="+data.egfr+"]").attr("checked",true);
				$("input[name='smoke'][value="+data.smoke+"]").attr("checked",true);
				$("#medical_history").val(data.medical_history);
				choose_open();
				addPthlgyDialog.show();		
			}
			else
			{
				messageAlert(0,"该患者已被删除！",function(){
					choose_close(),
					this.close(),
					showPthlgyPageDataList(1)
					});
			}
		}
	});
	
}

/**
 *	表单 单选框初始化 
 */
function pthlgySearchInit()
{
	var zlbwUrl = projectName + "/pthlgy/getZlbwList.do?date=" + new Date().getTime();
	$.ajax({
		url: zlbwUrl,
		async: false,
		success: function(data,result){
			for(var i = 0; i < data.length; i++)
			{
				$("#pthlgy_zlbwSelect").append("<option>" + data[i] + "</option>");
				$("#zlbw_radio").append("<label class='radio_biaodan' ><input name='tumor_site' value='" + data[i] + "'type='radio'>" + data[i] + "</label>");
			}
		}
	});
	
	var fhcdUrl = projectName + "/pthlgy/getFhcdList.do?date=" + new Date().getTime();
	$.ajax({
		url: fhcdUrl,
		async: false,
		success: function(data,result){
			for(var i = 0; i < data.length; i++)
			{
				$("#pthlgy_fhcdSelect").append("<option>"+data[i]+"</option>");
				$("#fhcd_radio").append("<label class='radio_biaodan' ><input name='dffrnttn' value='" + data[i] + "'type='radio'>" + data[i] + "</label>");
			}
		}
	});
	
	var tnmUrl = projectName + "/pthlgy/getTnmList.do?date=" + new Date().getTime();
	$.ajax({
		url: tnmUrl,
		async: false,
		success: function(data,result){
			for(var i = 0; i < data.length; i++)
			{
				$("#pthlgy_tnmSelect").append("<option>"+data[i]+"</option>");
				$("#tnm_radio").append("<label class='radio_biaodan' ><input name='tnm' value='" + data[i] + "'type='radio'>" + data[i] + "</label>");
			}
		}
	});
	
	var bllxUrl = projectName + "/pthlgy/getBllxList.do?date=" + new Date().getTime();
	$.ajax({
		url: bllxUrl,
		async: false,
		success: function(data,result){
			for(var i = 0; i < data.length; i++)
			{
				$("#pthlgy_bllxSelect").append("<option>"+data[i]+"</option>");
				$("#bllx_radio").append("<label class='radio_biaodan' ><input name='pathology' value='" + data[i] + "'type='radio'>" + data[i] + "</label>");
			}
		}
	});
}
/***************************************************************
							患者分页
***************************************************************/
/**
 *	患者分页对象 
 */
var pthlgyPageInfo={
		orderBy:null,
		order:"desc",
		pageNo:"1",
};


/**
 * 查询患者数据
 */
function showPthlgyPageDataList(pageNo)
{
	pthlgyPageInfo.pageNo = pageNo;
	var search_mrn = getSearch_mrn("pthlgy");
	var tumor_site = $("#pthlgy_zlbwSelect").val();
	var dffrnttn = $("#pthlgy_fhcdSelect").val();
	var tnm = $("#pthlgy_tnmSelect").val();
	var pathology = $("#pthlgy_bllxSelect").val();
	var egfr = $("#pthlgy_egfrSelect").val();
	if(egfr == "突变")
	{
		egfr = 1;
	}
	else if(egfr == "未突变")
	{
		egfr = 0;
	}
	var smoke = $("#pthlgy_smokeSelect").val();
	if(smoke == "有")
	{
		smoke = 1;
	}
	else if(smoke == "无")
	{
		smoke = 0;
	}
	var pthlgyPageInfoString = JSON.stringify(pthlgyPageInfo);
	window.location.href = projectName + "/pthlgy/getPagePthlgy.do?PageInfo=" + pthlgyPageInfoString + "&mrn=" + search_mrn + "&tumor_site=" + tumor_site
		+ "&dffrnttn=" + dffrnttn + "&tnm=" + tnm + "&pathology=" + pathology + "&egfr=" + egfr + "&smoke=" + smoke;
}

function pthlgyHuiTian(zlbw,fhcd,tnm,bllx,egfr,smoke)
{
	$("#pthlgy_zlbwSelect").val(zlbw);
	$("#pthlgy_fhcdSelect").val(fhcd);
	$("#pthlgy_tnmSelect").val(tnm);
	$("#pthlgy_bllxSelect").val(bllx);
	if(egfr == "1")
	{
		egfr = "突变";
	}
	else if(egfr == "0")
	{
		egfr = "未突变";
	}
	if(smoke == "1")
	{
		smoke = "有";
	}
	else if(smoke == "0")
	{
		smoke = "无";
	}
	$("#pthlgy_egfrSelect").val(egfr);
	$("#pthlgy_smokeSelect").val(smoke);
}

/***************************************************************
							表单验证
***************************************************************/
